/************************************************************************************************
 * test examples of 100 interesting program in C
 * test 011.c
 * Sleep or Fish
 ***********************************************************************************************/

#include <stdio.h>

/*
 * this problem provide a way to process bissextile and data
 */

int bissextile[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int debissextile[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int isBissextile(int year)
{
	if ((year%4 == 0 && year%100 != 0) || (year%400 == 0))
		return(1);
	else return(0);
}

int main()
{
	/* examine days in bissextile/debissextile array */
	int i = 0;
	int days_in_byear = 0, days_in_dyear = 0;
	for (i = 1; i <=12; i++)
	{
		days_in_byear += bissextile[i];
	}
	if (days_in_byear == 366)
		printf("bissextile year check OK.\n");
	for (i = 1; i <= 12; i++)
	{
		days_in_dyear += debissextile[i];
	}
	if (days_in_dyear == 365)
		printf("debissextile year check OK.\n");

	int year = 0, month = 0, day = 0;
	printf("Plz input date in format \"year month day\": ");
	scanf("%d %d %d", &year, &month, &day);
	printf("Input data is %d/%d/%d\n", year, month, day);
	int total_days = 0;
	for (i = 1990; i < year; i++)
	{
		if (isBissextile(i))
			total_days += 366;
		else
			total_days += 365;
	}
	if (isBissextile(year))
	{
		for (i = 1; i < month; i++)
			total_days += bissextile[i];
	}
	else
	{
		for (i = 1; i < month; i++)
			total_days += debissextile[i];
	}
	total_days += day;
	printf("Total %d days since 1900-01-01\n", total_days);
	int day_in_five = total_days % 5;
	if (day_in_five == 1 || day_in_five == 2 || day_in_five == 3)
		printf("Today is fishing\n");
	else
		printf("Today is sleeping\n");
	
}

